package com.hzqiuxm.tdddemo001.junit5demo.player;

/**
 * Copyright © 2021年 tdd-demo-001. All rights reserved.
 *
 * @author 临江仙 hzqiuxm@163.com
 * 玩家服务
 * @date 2021/2/23 12:25
 */
public class PlayerService {

    private final PlayerDAO playerDAO;

    public PlayerService(PlayerDAO dao){
        this.playerDAO = dao;
    }

    /**
     * 玩家运势解析
     */
    public String  fortureAnalyze(int playerId){
        Player player = getPlayer(playerId);

        String fortureResult = nameAnalyze(player.getName());
        // ... 假设还有其它的一些处理

        return fortureResult;
    }


    /**
     * 玩家展示名称修改
     */
    public boolean  changeShowName(int playerId,String newShowName){
        Player player = getPlayer(playerId);

        player.setShowName(newShowName);
        playerDAO.update(player);

        return true;
    }



    private Player getPlayer(int playerId) {
        return this.playerDAO
                .fetch(playerId)
                .orElseThrow(PlayerException::new);
    }
    /**
     * 名字分析
     * @param name 名字
     * @return
     */
    private String  nameAnalyze(String name){
        return name + " 乃大侠之像，维护世界和平任务就靠你了！";
    }
}
